package com.enjoy.controller;

import ctd.net.rpc.Client;
import ctd.net.rpc.balance.FixedHostBalance;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/web")
public class WebController {

    private final Logger logger = LoggerFactory.getLogger(WebController.class);

    @RequestMapping(value = "/getMsg", method = RequestMethod.GET)
    public String getMsg() {
        try {
            TimeUnit.SECONDS.sleep(1);
            Object msg = Client.rpcInvoke("enjoy.helloService", "getMsg", new Object[]{"aa"}, null, new FixedHostBalance("10.1.1.183:8080"));

            logger.info("msg = {}", msg);

        } catch (Exception e) {
            logger.error(e.getMessage());
            return "fail";
        }
        return "success";
    }
}
